<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 200px;
        color: rgb(241, 108, 12);
        background: cyan;
      }
      .box::after {
        content: "123";
        width: 50px;
        height: 50px;
      }
    </style>
  </head>
  <body>
    <div class="box">asdfsadgadsghds</div>
    <script>
      var boxEle = document.querySelector(".box");
      var res = getComputedStyle(boxEle)["color"];
      console.log(res);
      var res2 = getComputedStyle(boxEle, "after")["height"];
      console.log(res2);

      // 2.如果是ie8或者以下浏览器 需要使用  currentStyle
      // var res =  boxEle.currentStyle.width;
      // console.log(res);

      // 兼容性的函数；
      function getStyle(ele, styleName) {
        if (window.getComputedStyle) {
          return getComputedStyle(ele, null)[styleName];
        } else {
          return ele.currentStyle[styleName];
        }
      }
      var res = getStyle(boxEle, "width");
      console.log(res);
    </script>
  </body>
</html>
